Repository navigation
add fix for 'No Such Window' error - #394
Conversation
reason: from 6.4 secotion in http://www.w3.org/TR/webdriver/, it says: Once the window has closed, future commands must return a status code of no such window until a new window is selected for receiving commands. how to fix: 1. let close_window() automaticly switches to prevoius window; 2. capture NoSuchWindowException when select_window() / _select_matching()/get_current_window_handle()
|
I also need you to write some tests and update the changelog. |
|
should I put the test case in /test/acceptance/open_and_close.txt? |
|
Yeah, that sounds good to me. |
|
It is very useful to surface window handle to users that want to have the 'correct way' - comparing window handle sets, to switch window. If we do this way, the fix here for 'Close Window' is not required. instead, my new proposal is to update 'Select Window' and add 2 keywords: Close Window And Switch To | locator=NoneThis will close current window and then switch to window if locator is given. locator can be name, title, url, handle, ..., the same as 'Select Window' requires. ${previous_window}= | Select Window | locator=NoneThis will switch to window matching locator and return previous window's handle. locator can be name, title, url, handle of target window, or a handle list to exclude in order to find new window. If locator is 'self', only return current window handle. ${window_list}= | List WindowsThis will return a list of all opened window handles in same session not assuming its order. Above changes should not impact existing usage of 'Close Window' and 'Select Window', and can offer the strict 'correct way' for using handle to switch window. example 1: Open Browser
${main_window}= | Select Window | selfA user can switch to correct window like below: ${all_old_windows}= | List Windows
Click Link | xxx | # or any other action that generates a new window
${parent_window}= | Select Window | ${all_old_windows}
Close Window And Switch To | ${parent_window}Additional proposal: So an additional question is, should we also offer a express way to select the last-position indexed window as new window without the need to comparing with old window set? I guess this will be correct in 99% cases. ${parent_window}= | Select Window | new | #use window list instead 'new' to exclude them if disordered |
Keywords right after keyword 'Close Windwo' will fail due to NoSuchWinowExecption: 1. keyword 'Select Window' with named argument 'name=xxx'/'title=xxx'/'url=xxx', fixed _select_matching() as it calls get_current_window_handle() 2. keyword 'Get Window Ids/Names/Titles', will fail on NoSuchWinowExecption, fixed _get_window_infos() as it calls get_current_window_handle() Also reversed close_window() (not switching to prevoius window)
|
Anyway this PR should focus on NoSuchWindowException fixing. I raised another PR #395 for improve selecting new window with handles. I reversed the change for 'Close Window' and only deal with this exception in _get_window_infos() and _select_matching(). I test the PR against my real web server and it works well. however I did not add test code to acceptance test as I can not get its test server started smoothly to pass testing -- tried activepython2.7.8 with chrome/fireforx on win8.1 and winxp... |
|
Run |
|
Added two test cases and tested that they reproduce the issues and verify the fix. |
|
Okay, I'm back from vacation so I have a bit of time to review this. I might take a little time though, because I want to test this out myself before merging. |
|
Hey @divfor, this looks good to me. I've tested it, verified the failures on master, and verified the working solution. I'm going to go ahead and merge this. Thanks for your contribution! |
add fix for 'No Such Window' error
reason:
from 6.4 secotion in http://www.w3.org/TR/webdriver/, it says:
Once the window has closed, future commands must return a status code of
no such window until a new window is selected for receiving commands.
how to fix:
_select_matching()/get_current_window_handle()